package pers.qianyu.month_202102.date_20210222;

import pers.qianyu.util.model.*;

/**
 * 面试题 17.12. BiNode
 * https://leetcode-cn.com/problems/binode-lcci/
 *
 * @author mizzle rain
 * @date 2021-02-22 15:01
 */
public class ConvertBiNode {
    TreeNode pre = null, head = null;

    public TreeNode convertBiNode(TreeNode root) {
        if (root == null) return root;
        recur(root);
        return head;
    }

    private void recur(TreeNode node) {
        if (node == null) return;
        recur(node.left);
        if (pre == null) {
            head = node;
        } else {
            pre.right = node;
            node.left = null;
        }
        pre = node;
        recur(node.right);
    }
}
